using System;
using System.Collections.Generic;
using System.Text;
using Tools;

namespace Test.Support {
	class XDockLabels {
		static void MainX() {

			string s="XSOV#2P#7";
			s=s.Replace("#","-");
			s=s.Substring(0,s.Length-1);

			Console.WriteLine(LocationCD.ApplyCheckDigit(s));

		}
	}
	public class LocationCD {
		public static char GetCheckDigit(string code) {
			char result=' ';
			string transformedCode=GetTransformedCode(code);
			int weight=transformedCode.Length+1;
			int accumulator=0;
			for(int index=0;index<transformedCode.Length;index++)
			{
				accumulator+=(transformedCode[index]-'0')*weight;
				weight--;
			}
			accumulator=accumulator%11;
			result=(accumulator==10)?'U':(char)('0'+(char)accumulator);
			return result;
		}

		public static string ApplyCheckDigit(string code) {
			return string.Format("{0}{1}",code,GetCheckDigit(code));
		}

		public static bool Check(string code) {
			return (code[code.Length-1]==GetCheckDigit(code.Substring(0,code.Length-1)));
		}

		private static string GetTransformedCode(string code) {
			StringBuilder result=new StringBuilder();
			for(int index=0;index<code.Length;index++)
			{
				if(char.IsDigit(code[index]))
				{
					result.Append(code[index]);
				}
				else
				{
					result.Append(string.Format("{0:00}",code[index]-'A'+1));
				}
			}
			return result.ToString();
		}

	}
}
